<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">-->

<!DOCTYPE html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>CorkBoard It!</title>
</head>

<body>

<?php
	session_start();
	
	$host="localhost";
	$username="root";
	$password="";
	$database="cs4400_group17";

	mysql_connect($host,$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
	
	$username = $_SESSION['userName'];
	$useremail = $_SESSION['userEmail'];
?>

<div id="masthead">
	<h1>CorkBoard<span style="color:red;">It</span></h1>
	<p style="color:orange;margin-top:-10px"><b>Explore. Share. Inspire.</b></p>
</div>

<div id="container">
	<div id="page_content">
		<h1>Home Page for
		<!-- USERS NAME -->
		<?php echo $username . ' (' .$useremail . ')';?>
		</h1>
		
		<h2>Recent CorkBoard Updates</h2>
		
		<?php $sql2 = "CREATE VIEW myView AS SELECT followee FROM userfollows WHERE Email='$useremail';";
		      mysql_query($sql2);
		      $sql = "SELECT * FROM corkboard JOIN myView WHERE Email = followee;";
			$result = mysql_query($sql);
			while ($rows = mysql_fetch_array($result)) {
				$corkboardEmail = $rows['Email'];
				$corkboardTitle = $rows['Title'];
				$privSql = "SELECT Password From privatecb WHERE Email='$corkboardEmail' AND Title ='$corkboardTitle'";
				$privResult = mysql_query($privSql);
				$privRow = mysql_fetch_array($privResult);
				$privPassword = $privRow[0];
				
				if($privPassword){
					$visibility = "--This corkboard is private--";
				}else{
					$visibility = "";
				}
		?>
		<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
			<tr>
				<td>
					<form action='CheckCorkboardVisibility.php' method='post'>
						<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
							<tr>
								<td>Email</td>
								<td>:</td>
								<td><?php echo $rows['Email']; ?>
									<input type="hidden" name="corkboardEmail" value="<?php echo $rows['Email'];?>"></td>
							</tr>
							<tr>
								<td>Title</td>
								<td>:</td>
								<td><?php echo $rows['Title']; ?>
									<input type="hidden" name="corkboardTitle" value="<?php echo $rows['Title'];?>"></td>
							</tr>
							<tr>
								<td width="117">CategoryName</td>
								<td width="14">:</td>
								<td width="357"><?php echo $rows['CategoryName']; ?>
									<input type="hidden" name="corkboardCategoryName" value="<?php echo $rows['CategoryName'];?>"></td>
							</tr>
							<tr>
								<td>LastUpdate</td>
								<td>:</td>
								<td><?php echo $rows['LastUpdate']; ?>
									<input type="hidden" name="corkboardLastUpdate" value="<?php echo $rows['LastUpdate'];?>"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td><?php echo $visibility?></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td><input type="submit" value="Go to Corkboard"/></td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</table>
		<BR>
		<?php
			}
			$count=mysql_num_rows($result);
			
			if($count < 1){
				echo "<p>Either you're not following anyone or they have no CorkBoards</p>";
			}
		$sql = "DROP TABLE myView;";
		mysql_query($sql);
		?>
		
		<p>Your CorkBoards</p>
		
		<?php $sql = "SELECT * FROM corkboard WHERE Email='$useremail'";
			$result = mysql_query($sql);
			while ($rows = mysql_fetch_array($result)) {
				$corkboardEmail = $rows['Email'];
				$corkboardTitle = $rows['Title'];
				$privSql = "SELECT Password From privatecb WHERE Email='$corkboardEmail' AND Title ='$corkboardTitle'";
				$privResult = mysql_query($privSql);
				$privRow = mysql_fetch_array($privResult);
				$privPassword = $privRow[0];
				
				if($privPassword){
					$visibility = "--This corkboard is private--";
				}else{
					$visibility = "";
				}
		?>
		<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
			<tr>
				<td>
					<form action='CheckCorkboardVisibility.php' method='post'>
						<input type="hidden" name="corkboardEmail" value="<?php echo $useremail;?>"></td>
						<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
							<tr>
								<td>Title</td>
								<td>:</td>
								<td><?php echo $rows['Title']; ?>
									<input type="hidden" name="corkboardTitle" value="<?php echo $rows['Title'];?>"></td>
							</tr>
							<tr>
								<td width="117">CategoryName</td>
								<td width="14">:</td>
								<td width="357"><?php echo $rows['CategoryName']; ?>
									<input type="hidden" name="corkboardCategoryName" value="<?php echo $rows['CategoryName'];?>"></td>
							</tr>
							<tr>
								<td>LastUpdate</td>
								<td>:</td>
								<td><?php echo $rows['LastUpdate']; ?>
									<input type="hidden" name="corkboardLastUpdate" value="<?php echo $rows['LastUpdate'];?>"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td><?php echo $visibility?></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td><input type="submit" value="Go to Corkboard"/></td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</table>
		<BR>
		<?php
			}
			mysql_close();
		
			$count=mysql_num_rows($result);
			
			if($count < 1){
				echo "<p>You currently have no CorkBoards</p>";
			}
		?>
		
		<form action='CheckPassword.php' method='post'><input type='submit' name='checkpassword' value='Check Password/PIN'/></form>
		<form action='AddCorkboard.html' method='get'><input type="submit" value="Add CorkBoard"/></form><br/>
		<form name="tags.php" action="popularTags.php" method="get"><input type="submit" value="Popular Tags"/></form>
		
	</div>
</div>

<div id="footer">
	
	<h3> Search For Pushpins </h3>
	<form action="searchPushpin.php" method="get">
				Description: <input type="text" name="description"><br>
				Corkboard Title: <input type="text" name="corkBoardTitle"><br>
				Tags: <input type="text" name="tags"><br>
				<input type="Submit" value="Search">
			</form>

</div>

</body>

</html>